package cn.anecansaitin.inet.mixins;

import cn.anecansaitin.inet.TranslateHelper;
import mcjty.rftoolsbase.api.xnet.gui.IEditorGui;
import mcjty.rftoolsbase.api.xnet.helper.AbstractConnectorSettings;
import mcjty.xnet.apiimpl.logic.LogicConnectorSettings;
import mcjty.xnet.apiimpl.logic.Sensor;
import net.minecraft.core.Direction;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;

import java.util.List;

@Mixin(LogicConnectorSettings.class)
public abstract class LogicConnectorSettingMixin extends AbstractConnectorSettings {
    public LogicConnectorSettingMixin(@NotNull Direction side) {
        super(side);
    }

    @Shadow
    private LogicConnectorSettings.LogicMode logicMode;
    @Shadow
    private List<Sensor> sensors;
    @Shadow
    private int speed = 2;
    @Shadow
    private Integer redstoneOut;

    @Override
    public void createGui(IEditorGui gui) {
        advanced = gui.isAdvanced();
        String[] speeds;
        if (advanced) {
            speeds = new String[] { "5", "10", "20", "60", "100", "200" };
        } else {
            speeds = new String[] { "10", "20", "60", "100", "200" };
        }
        sideGui(gui);
        colorsGui(gui);
        redstoneGui(gui);
        gui.nl()
                .choices(LogicConnectorSettings.TAG_MODE, TranslateHelper.getText("inet.controller.setting.button.sensor.tooltip"), logicMode, LogicConnectorSettings.LogicMode.values())
                .choices(LogicConnectorSettings.TAG_SPEED, (logicMode == LogicConnectorSettings.LogicMode.SENSOR ? TranslateHelper.getText("inet.controller.setting.button.speed.tooltip2") : TranslateHelper.getText("inet.controller.setting.button.speed.tooltip1")), Integer.toString(speed * 5), speeds)
                .nl();
        if (logicMode == LogicConnectorSettings.LogicMode.SENSOR) {
            for (Sensor sensor : sensors) {
                sensor.createGui(gui);
            }
        } else {
            gui.label(TranslateHelper.getText("inet.controller.setting.label.redstone.text"))
                    .integer(LogicConnectorSettings.TAG_REDSTONE_OUT, TranslateHelper.getText("inet.controller.setting.label.redstone.tooltip"), redstoneOut, 40, 16)
                    .nl();
        }
    }
}
